//----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//----------------------------------------------------------------------------------


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public class SsdsConfig
{
    public Uri ServiceUri { get; set; }
    public string Authority { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }

    /// <summary>
    /// Generates the appropriate configuration information from the app.config 
    /// settings.  Use this to construct the necessary details for credentials
    /// and http service locations.
    /// </summary>
    /// <returns></returns>
    public static SsdsConfig Create()
    {
        return new SsdsConfig
        {
            ServiceUri = new Uri(ConfigurationSettings.AppSettings["serviceUri"]),
            Authority = ConfigurationSettings.AppSettings["authority"],
            Username = ConfigurationSettings.AppSettings["username"],
            Password = ConfigurationSettings.AppSettings["password"]
        };
    }

    /// <summary>
    /// Get the proper Authority URI based on configuration settings
    /// </summary>
    /// <returns></returns>
    public Uri GetAuthority()
    {
        return new Uri(
            String.Format("https://{0}.{1}/v1/", this.Authority, this.ServiceUri.Host)
            );
    }

    /// <summary>
    /// Creates a URI for a container based on configuration settings
    /// </summary>
    /// <param name="container">container name</param>
    /// <returns></returns>
    public Uri GetContainer(string container)
    {
        return new Uri(
            String.Format("{0}{1}", this.GetAuthority(), container)
            );
    }
}